/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.camachosanchez.mechanics;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;

/**
 *
 * @author Rolando
 */
public class Eje {

    private int posicion;
    private int x;
    private int y;
    private int alto;
    private int ancho;
//    private final Image sin_llanta = (new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/notire.png"))).getImage();
    private boolean estaMontado;
    private boolean dibujarPosicion;

    public Eje(int x, int y, int ancho, int alto, int posicion, boolean estaMontado, boolean dibujarPosicion) {
        this.x = x;
        this.y = y;
        this.alto = alto;
        this.ancho = ancho;
        this.estaMontado = estaMontado;
        this.dibujarPosicion = dibujarPosicion;
        this.posicion = posicion;
    }

    public int getAlto() {
        return alto;
    }

    public void setAlto(int alto) {
        this.alto = alto;
    }

    public int getAncho() {
        return ancho;
    }

    public void setAncho(int ancho) {
        this.ancho = ancho;
    }

    public boolean isEstaMontado() {
        return estaMontado;
    }

    public void setEstaMontado(boolean estaMontado) {
        this.estaMontado = estaMontado;
    }

    public int getPosicion() {
        return posicion;
    }

    public void setPosicion(int posicion) {
        this.posicion = posicion;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public boolean estaDentro(Point p) {
//        if(p.x<x || (p.x>(x+ancho)))
        Rectangle r = new Rectangle(x, y, ancho, alto);
        return r.contains(p);
    }

    public void graficar(Graphics2D graphics) {
//        graphics.drawImage(sin_llanta, x, y, ancho, alto, null);
        graphics.setColor(Color.white);
//        graphics.setStroke(new BasicStroke(1.2f));
        float dash[] = {2.0f};
        graphics.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));
        graphics.fillRoundRect(x + 5, y + 5, ancho - 10, alto - 10, 30, 30);
        graphics.setColor(Color.black);
        graphics.drawRoundRect(x + 5, y + 5, ancho - 10, alto - 10, 30, 30);
        graphics.setStroke(new BasicStroke());
        if (dibujarPosicion) {
            FontMetrics metrics = graphics.getFontMetrics(graphics.getFont());
            String pos = posicion <= 0 ? "R" : "" + posicion;
            int hgt = metrics.getHeight();
            int adv = metrics.stringWidth(pos);
            graphics.setColor(Color.yellow);
            graphics.fillOval(x - adv / 2 + (ancho / 2) - 4, y + 2 + (alto / 2) - 3 * hgt / 4, 2 * adv, hgt);
            graphics.setColor(Color.black);
            graphics.drawOval(x - adv / 2 + (ancho / 2) - 4, y + 2 + (alto / 2) - 3 * hgt / 4, 2 * adv, hgt);
            graphics.setColor(Color.black);
            graphics.drawString(pos, x + (ancho / 2) - 3, y + (alto / 2) + 3);
        } else {
            graphics.drawLine(x + (ancho / 2) - 6, y + alto / 2, x + (ancho / 2) + 6, y + alto / 2);
            graphics.drawLine(x + ancho / 2, y + (alto / 2) - 6, x + ancho / 2, y + (alto / 2) + 6);
        }
    }
}
